package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardReport;
import com.qf.serivice.ElasticSearchService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * projectName: sms-platform02
 *
 * @author: 元
 * time: 2021/10/21 0021 15:55
 * description:保存发送日志到ES服务器
 */
@Component
@Slf4j
public class ReportUpdateListener {

    @Autowired
    private ElasticSearchService elasticSearchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT)
    public void consume(StandardReport standardReport, Channel channel, Message message) throws IOException {

        //当有新的日志数据时,修改ES日志数据
        elasticSearchService.updateLog(standardReport);

       //手动ACK确认
       channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }
}
